using System;
using UnityEngine;

public class MovableRandomWalk : MonoBehaviour
{
	[Serializable]
	public class WalkAnimation
	{
		public RuntimeAnimatorController animation;

		public float minSpeed;

		public float maxSpeed;
	}

	[Serializable]
	public class EditorReferences
	{
		public WalkAnimation[] walkAnimations;

		public float minXOffset;

		public float maxXOffset;

		public WalkAnimation GetRandomAnimation()
		{
			return walkAnimations[UnityEngine.Random.Range(0, walkAnimations.Length)];
		}
	}

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private bool _isInitialized;

	private bool _isWalking;

	private void Start()
	{
		_isInitialized = true;
		_isWalking = false;
		SetRandomWalk();
	}

	private void OnEnable()
	{
		if (_isInitialized)
		{
			SetRandomWalk();
		}
	}

	private void OnDisable()
	{
		_isWalking = false;
	}

	private void SetRandomWalk()
	{
		if (!_isWalking)
		{
			WalkAnimation randomAnimation = references.GetRandomAnimation();
			MovableAnimation component = GetComponent<MovableAnimation>();
			MovableSplineAdapter component2 = GetComponent<MovableSplineAdapter>();
			if (UnityEngine.Random.value < 0.5f)
			{
				component2.SetSpeed(UnityEngine.Random.Range(randomAnimation.minSpeed, randomAnimation.maxSpeed));
			}
			else
			{
				component2.SetSpeed(0f - UnityEngine.Random.Range(randomAnimation.minSpeed, randomAnimation.maxSpeed));
			}
			component2.SetXOffset(UnityEngine.Random.Range(references.minXOffset, references.maxXOffset));
			component.SetAnimation(randomAnimation.animation);
			_isWalking = true;
		}
	}
}
